/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
 */
package td.domain;

import java.util.ArrayList;

import td.domain.util.StatisticalComparison;

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Ignore;

/**
 * The actual grouping of a Tag as in the definition of a given Tag (vs. as
 * instance of a Tag applied to a given thought).
 * 
 * @author Artem Shamsutdinov
 */
@Entity
public class TagDef extends Hierarchy<TagDef> {

	private static final long serialVersionUID = 762719105942930832L;

	public static StatisticalComparison currentComparisonType = StatisticalComparison.NUMBER_OF_THOUGHT_READS;

	private Long numCategories = 0L;
	private Long directNumCategories = 0L;

	@Ignore
	private ArrayList<Tag> tagged;

	public TagDef() {
		super();
	}

	public TagDef(String name) {
		super(name);
	}

	public TagDef(String name, String description, TagDef parentTag) {
		super(name, description, parentTag);
	}

	@Override
	protected TagDef getInstance(String name, String description, TagDef parent) {
		return new TagDef(name, description, parent);
	}

	public ArrayList<Tag> getTagged() {
		return tagged;
	}

	public void setTagged(ArrayList<Tag> tagged) {
		this.tagged = tagged;
	}

	@Override
	public StatisticalComparison getComparisonType() {
		return currentComparisonType;
	}

	@Override
	public int compareTo(Statistical otherStats) {
		if (otherStats instanceof TagDef) {
			TagDef otherTagDefinition = (TagDef) otherStats;
			switch (getComparisonType()) {
			case NUMBER_OF_CATEGORIES:
				return otherTagDefinition.numCategories
						.compareTo(numCategories);
			case DIRECT_NUMBER_OF_CATEGORIES:
				return otherTagDefinition.directNumCategories
						.compareTo(directNumCategories);
			default:
				return super.compareTo(otherTagDefinition);
			}
		}
		throw new RuntimeException(
				"Tag Definitions should only be compared to other Tag Definitions");
	}

	/* (non-Javadoc)
	 * @see td.domain.StatisticalGrouping#getTypeForUrl()
	 */
	@Override
	public String getTypeForUrl() {
		return GroupType.TAG.name();
	}
}
